package vn.edu.saigontech.ncms.model.teaching;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.OptimisticLockType;

import vn.edu.saigontech.ncms.model.BaseEntity;
import vn.edu.saigontech.ncms.model.info.Offering;
import vn.edu.saigontech.ncms.model.info.Teacher;
import vn.edu.saigontech.ncms.util.DateUtil;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, optimisticLock = OptimisticLockType.ALL)
@Table(name = "ncms_teaching_switch")
@SuppressWarnings("serial")
public class TeachingSwitch extends BaseEntity {
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "offering_id", nullable = false)
	private Offering offering;

	@JoinColumn(name = "main_day")
	private int mainDay;
	
	@ManyToOne
	@JoinColumn(name = "main_teacher_id")
	private Teacher mainTeacher;

	@ManyToOne
	@JoinColumn(name = "in_place_teacher_id")
	private Teacher inplaceTeacher;

	@Temporal(TemporalType.DATE)
	@Column(name = "from_date")
	private Date fromDate;

	@Temporal(TemporalType.DATE)
	@Column(name = "to_date")
	private Date toDate;

	@Column(name = "comment", length = 4000)
	private String comment;

	public boolean contains(Date date) {
		return DateUtil.isBetween(date, this.fromDate, this.toDate);
	}
	
	public Offering getOffering() {
		return offering;
	}

	public void setOffering(Offering offering) {
		this.offering = offering;
	}

	public Teacher getMainTeacher() {
		return mainTeacher;
	}

	public void setMainTeacher(Teacher mainTeacher) {
		this.mainTeacher = mainTeacher;
	}

	public int getMainDay() {
		return mainDay;
	}

	public void setMainDay(int mainDay) {
		this.mainDay = mainDay;
	}

	public Teacher getInplaceTeacher() {
		return inplaceTeacher;
	}

	public void setInplaceTeacher(Teacher inplaceTeacher) {
		this.inplaceTeacher = inplaceTeacher;
	}

	public Date getFromDate() {
		return fromDate;
	}

	public void setFromDate(Date fromDate) {
		this.fromDate = fromDate;
	}

	public Date getToDate() {
		return toDate;
	}

	public void setToDate(Date toDate) {
		this.toDate = toDate;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
}